<%--
  Created by IntelliJ IDEA.
  User: shen
  Date: 2020/2/8
  Time: 9:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
    <base href="<%=basePath%>">
    <title>新增单选题</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">

    <link rel="stylesheet" type="text/css" href="js/easyui/themes/default/easyui.css">

    <script type="text/javascript" src="js/jquery-2.0.0.js"></script>
    <script type="text/javascript" src="js/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="js/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="js/easyui/easyui.dateformat.js"></script>
    <link href="font-awesome/css/font-awesome.css" rel="stylesheet">

    <link href="css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <%@include file="../common_resource.jsp" %>
    <style type="text/css">
        .main_body{
            /*position: relative;
            top:190px;*/
            font-size: 14px;
        }
        .listDiv{
            font-size: 13px;
        }
    </style>
    <script type="text/javascript">

       $.getJSON('Kld/selectAllLev/0', function (res) {
        var qxid = $('#questCatagory');

        $.each(res, function (index,item) {
            console.log('%i - %o', index, item);
            qxid.append('<option value="' + item.levKldID +'">' + item.levKldCtgr + '</option>');
        })
     });

       // 加二级知识点下拉列表
       function changeLevKld(ele) {
           var  levKldID= ele.options[ele.selectedIndex].value;
           $.getJSON('Kld/selectAllSecByLevID/0',{levKldID:  levKldID},function (res) {
               var secKldIDFrom = $('#secKldIDFrom');
               secKldIDFrom.empty();
               $.each(res, function (index,item) {
                   console.log('%i - %o', index, item);
                   secKldIDFrom.append('<option value="' + item.secKldID +'">' + item.secKldCtgr + '</option>');
               })
           });
       }


    </script>
    <script>
        // 将选中的知识点添加到提交处
        function addSecTo(secKldIDFrom,secKldIDTo,msg) {

            var secKldIDFrom = $("#" + secKldIDFrom);
            console.log(secKldIDFrom);
            var secKldIDTo = $("#" + secKldIDTo);
            var fromValue = secKldIDFrom.val() == null ? "" : $.trim(secKldIDFrom.val());// 获取select选择的或者text的value
           if (fromValue == ""||fromValue=="请选择..") {
                alert(msg);
                return;
            }
            if(secKldIDTo.find("option[value='"+fromValue+"']")[0]){
                alert("不能重复添加！");
                return;
            }

            var	secKldCtgr = secKldIDFrom.find("option:selected").text();// 获取select选择的text
            var secKldID = secKldIDFrom.find("option:selected").val();// 获取select选择的code
            secKldIDTo.append('<option value="' + secKldID +'">' + secKldCtgr + '</option>');// 为select追加一个option(下拉项)
            secKldIDTo.get(0).selectedIndex = 0;// 设置select索引值为0的项选中

        }
        // 删除select的option
        function delSec(secKldIDTo, msg) {
            var select = $("#" + secKldIDTo);
            var toValue = select.val() == null ? "" : $.trim(select.val());
            if (toValue == "") {
                alert(msg);
            } else {
                select.find("option[value='" + select.val() + "']").remove();// 删除select中选择的option
            }

        }

    </script>
    <script >
        $(function(){
            var codeFormat = '在下列给出的协议中，(     )是TCP/IP的应用层协议？';
            $("#use").click(function(){
                $("#tg").val('');
                var question=$("#tg").val();
                $("#tg").val(question+codeFormat);//$("#code").val()
            });
        });

        function to(){
            location.href="question/selectAllSQuestions/0";
        }

        /*判断是否成功插入单选题*/
        <c:if test="${not empty sessionScope.insertSQuestion}">
        $(function(){
            $("#insertSuccessModal").modal();
        });
        </c:if>
        <c:if test="${0 eq sessionScope.insertSQuestion}">
        $(function(){
            $("#insertFailModal").modal();
        });
        </c:if>

        /*ajax发异步请求并判断是否成功插入单选题*/
        function insertSQ() {
            $.getJSON('question/insertSQuestion/1',function (res) {
                if(res.insertSQuestion!=0){
                    swal({
                        title: "新增单选题",
                        text: "新增单选题信息成功",
                        type: "success"
                    },function () {
                        location.reload();
                    });
                }else{
                    swal({
                        title: "新增单选题",
                        text: "新增单选题信息失败，请重新检查",
                        type:"error"
                    });
                }

            })

        }

    </script>
</head>
<body class="main_body">
<div class="container container-1180" >
    <div class="col" style="margin-top: 10px;">
        <div class="panel panel-info" >
            <div class="panel-heading">
                <span ><i class="fa fa-user"></i></span> <label><font style="font-weight: bold;margin-left: 10px;font-size: 17px">新&nbsp;增&nbsp;单&nbsp;选&nbsp;题</font></label>

                <label style="float: right;">
                    <div class="button_bar">
                        <button class="btn btn-info btn-sm" onclick="to();">查询选题</button>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    </div>
                </label>
            </div>


            <div style="margin-top: 20px">
                <form id="singleForm" action="question/insertSQuestion/1" method="post">

                    <div class="question" style="margin-left: 160px;">
                        <div class="error invalid_error"><span></span><br/></div>
                        <div class="quest_body" style="margin-top:-5px;">
                            <label><font color="red"></b>*</font>&nbsp;试题主干</label><br/>
                            <textarea id="tg" name="question" rows="5" cols="118"  class="easyui-validatebox form-control"  required="true" style="width: 500px" placeholder="请输入单选题题干......"></textarea><br/>
                            <input id="use"  type="button" value="查看题目格式" class="btn btn-primary"/>
                        </div>
                        </br>
                        <div style="margin-top:10px; margin-left:5px;">
                            <div >
                                <div style="float:left;" >
                                    <label style="margin-right: 50px"><font color="red"></b>*</font>&nbsp;难度(请单击选择):</label>
                                    <select id="difficulty" name="difficulty"   style="width:120px;margin-left:123px;margin-top: -30px;" class="easyui-validatebox form-control"  required="true" >
                                        <option value="0.25">0.25</option>
                                        <option value="0.5">0.5</option>
                                        <option value="0.75">0.75</option>
                                    </select>
                                    <br/><br/>
                                </div>
                            </div>
                            <br/><br/>
                            <div style="float:left;margin-left: -250px">
                                    <label style="margin-left: 10px"><font color="red"></br>*</font>&nbsp;一级知识点(请单击选择)</label>
                                    <label id="questCtgrError" class="catagoryMsg"></label>

                                    <label style="margin-left: 40px"><font color="red"></br>*</font>&nbsp;二级知识点(可多选)</label>
                                    <label style="margin-left: 48px"><font color="red"></br>*</font>&nbsp;涉及的二级知识点(多选)</label></br>

                                    <jsp:include page="selectKld.jsp"></jsp:include>
                                    <br/>
                                </div>
                                <div style="clear: both;">
                                </div>
                            </div>
                            <div style="clear:both;border: 0px solid red;">
                                <table id="optionTbl" cellpadding="0" cellspacing="0" border="0px">
                                    <tr>
                                        <th width="18px">选项</th>
                                        <th>内容</th>
                                        <th width="60px">正确答案</th>
                                        <th rowspan="5" valign="middle">
                                            <div id="correctMsg" class="custome_error"></div>
                                        </th>
                                    </tr>
                                    </br>
                                    <tr>
                                        <td><font color="red"><b>*</b></font>A.</td>
                                        <td><textarea id="optionA" name="optionA" cols="65" class="easyui-validatebox form-control"  required="true" style="width: 300px;height: 40px" placeholder="请输入答案......"></textarea></td>
                                        <td><input type="radio" name="sCorrect" value="A" class="easyui-validatebox"  required="true" /></td>
                                    </tr>
                                    <tr >
                                        <td><font color="red"><b>*</b></font>B.</td>
                                        <td><textarea id="optionB" name="optionB" cols="65" class="easyui-validatebox form-control"  required="true" style="width: 300px;height: 40px" placeholder="请输入答案......"></textarea></td>
                                        <td><input type="radio" name="sCorrect" value="B"  class="easyui-validatebox"  required="true"/></td>
                                    </tr>
                                    <tr>
                                        <td><font color="red"><b>*</b></font>C.</td>
                                        <td><textarea id="optionC" name="optionC" cols="65" class="easyui-validatebox form-control"  required="true" style="width: 300px;height: 40px" placeholder="请输入答案......"></textarea></td>
                                        <td><input type="radio" name="sCorrect" value="C"  class="easyui-validatebox"  required="true"/></td>
                                    </tr>
                                    <tr>
                                        <td><font color="red"><b>*</b></font>D.</td>
                                        <td><textarea id="optionD" name="optionD" cols="65" class="easyui-validatebox form-control"  required="true" style="width: 300px;height: 40px" placeholder="请输入答案......"></textarea></td>
                                        <td><input type="radio" name="sCorrect" value="D"  class="easyui-validatebox"  required="true"/></td>
                                    </tr>
                                    <tr>
                                        <td><font color="red"></font>E.</td>
                                        <td><textarea id="optionE" name="optionE" cols="65" class="easyui-validatebox form-control"  style="width: 300px;height: 40px" placeholder="请输入答案......"></textarea></td>
                                        <td><input type="radio" name="sCorrect" value="E"  class="easyui-validatebox"  /></td>
                                    </tr>
                                    <tr id="emptyRow" style="height: 10px;"><td colspan="4"></td></tr>
                                </table>
                            </div>
                        </div>
                        <div style="margin-left:250px;width:300px;">
                            <button id="submit" type="submit" value="保存" class="btn btn-info" >保存</button>&nbsp;&nbsp;&nbsp;&nbsp;
                            <button type="reset" value="重置" class="btn btn-warning">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


<script src="bootstrap/js/bootstrap.min.js"></script>

<!-- 添加成功模态 -->
<div class="modal fade" id="insertSuccessModal" tabindex="-1" role="dialog"
     aria-labelledby="insertSuccessModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">×
                </button>
                <h2 class="modal-title" id="myModal1">
                    <i class="fa fa-twitch"></i> &nbsp;&nbsp;提示
                </h2>
            </div>
            <div class="modal-body" style="text-align:center;">
                <h3>单选题添加成功</h3>
            </div>
            <div class="modal-footer">
                <button id="closeModal" type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- 添加失败模态 -->
<div class="modal fade" id="insertFailModal" tabindex="-1" role="dialog"
     aria-labelledby="insertFailModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">×
                </button>
                <h2 class="modal-title" id="myModal2">
                    <i class="fa fa-twitch"></i> &nbsp;&nbsp;提示
                </h2>
            </div>
            <div class="modal-body" style="text-align:center;">
                <h3>单选题添加失败</h3>
            </div>
            <div class="modal-footer">
                <button  type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</body>
</html>
<c:remove var="insertSQuestion" scope="session"/>

